<?php

namespace JsonLowCode\UI;

use JsonLowCode\Schema;
use JsonLowCode\Traits\Props\HasTitle;

/**
 *
 * 代码显示组件 AppCode
 * @method static AppCode make(string $title,string $code = null) 代码显示组件 AppCode
 */
class AppCode extends Schema
{
    protected string $componentName = "AppCode";

    use HasTitle;

    public function __construct(string $title, string $code = null, string $bindName = null)
    {
        parent::__construct();
        $this->title($title);
        if($code){
            $this->code($code, $bindName);
        }
        $this->prop('readonly', true);
    }

    /**
     * @param string $code
     * @param string|null $bindStateName
     * @return $this
     */
    public function code(string $code, string $bindStateName = null): static
    {
        $bindName = $bindStateName?:"this.state.code_".uniqid();
        $this->modelValue($bindName,$code);
        return $this;
    }

    /**
     * @param int $type
     * @return $this
     */
    public function type(int $type = 0): static
    {
        return $this->prop('type', $type);
    }

    /**
     * 代码语言
     *  'php'|'html'|'xml'|'yaml'|'svg'|'js'|'ts'|'css'|'scss'|'less'|'json'|'sql'|'java'|'python'|'go'|'c'|'bash'|'shell'
     * @param string $language
     * @return $this
     */
    public function language(string $language = 'php'|'html'|'xml'|'yaml'|'svg'|'js'|'ts'|'css'|'scss'|'less'|'json'|'sql'|'java'|'python'|'go'|'c'|'bash'|'shell'): static
    {
        return $this->prop('language', $language);
    }


    /**
     * 是否显示行号
     * @param string|bool $bool
     * @return $this
     */
    public function showLine(string|bool $bool = true): static
    {
        return $this->prop('showLine', $bool);
    }
}
